home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / slide_image.pro < prev    next >
Text File  |  1997-07-08  |  8KB  |  216 lines

  1. ; $Id: slide_image.pro,v 1.6 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    SLIDE_IMAGE
  8. ;
  9. ; PURPOSE:
  10. ;    Create a scrolling graphics window for examining large images.
  11. ;    By default, 2 draw widgets are used.  The left draw widget shows
  12. ;    a reduced version of the complete image, while the draw widget on
  13. ;    the right displays the actual image with scrollbars that allow sliding
  14. ;    the visible window.
  15. ;
  16. ; CALLING SEQUENCE:
  17. ;    SLIDE_IMAGE [, Image]
  18. ;
  19. ; INPUTS:
  20. ;    Image:    The 2-dimensional image array to be displayed.  If this 
  21. ;        argument is not specified, no image is displayed. The 
  22. ;        FULL_WINDOW and SCROLL_WINDOW keywords can be used to obtain 
  23. ;        the window numbers of the 2 draw widgets so they can be drawn
  24. ;        into at a later time.
  25. ;
  26. ; KEYWORDS:
  27. ;      CONGRID:    Normally, the image is processed with the CONGRID
  28. ;        procedure before it is written to the fully visible
  29. ;        window on the left. Specifying CONGIRD=0 will force
  30. ;        the image to be drawn as is.
  31. ;
  32. ;  FULL_WINDOW:    A named variable in which to store the IDL window number of \
  33. ;        the non-sliding window.  This window number can be used with 
  34. ;        the WSET procedure to draw to the scrolling window at a later
  35. ;        point.
  36. ;
  37. ;    GROUP:    The widget ID of the widget that calls SLIDE_IMAGE.  If this
  38. ;        keyword is specified, the death of the caller results in the
  39. ;        death of SLIDE_IMAGE.
  40. ;
  41. ;    ORDER:    This keyword is passed directly to the TV procedure
  42. ;        to control the order in which the images are drawn. Usually,
  43. ;        images are drawn from the bottom up.  Set this keyword to a
  44. ;        non-zero value to draw images from the top down.
  45. ;
  46. ;     REGISTER:    Set this keyword to create a "Done" button for SLIDE_IMAGE
  47. ;        and register the widgets with the XMANAGER procedure.
  48. ;
  49. ;        The basic widgets used in this procedure do not generate
  50. ;        widget events, so it is not necessary to process events
  51. ;        in an event loop.  The default is therefore to simply create
  52. ;        the widgets and return.  Hence, when register is not set, 
  53. ;        SLIDE_IMAGE can be displayed and the user can still type 
  54. ;        commands at the "IDL>" prompt that use the widgets.
  55. ;
  56. ;    RETAIN:    This keyword is passed directly to the WIDGET_DRAW
  57. ;        function, and controls the type of backing store
  58. ;        used for the draw windows.  If not present, a value of
  59. ;        2 is used to make IDL handle backing store.
  60. ;
  61. ; SLIDE_WINDOW:    A named variable in which to store the IDL window number of 
  62. ;        the sliding window.  This window number can be used with the 
  63. ;        WSET procedure to draw to the scrolling window at a later 
  64. ;        time.
  65. ;
  66. ;    TITLE:    The title to be used for the SLIDE_IMAGE widget.  If this
  67. ;        keyword is not specified, "Slide Image" is used.
  68. ;
  69. ;    TOP_ID:    A named variable in which to store the top widget ID of the 
  70. ;        SLIDE_IMAGE hierarchy.  This ID can be used to kill the 
  71. ;        hierarchy as shown below:
  72. ;
  73. ;            SLIDE_IMAGE, TOP_ID=base, ...
  74. ;            .
  75. ;            .
  76. ;            .
  77. ;            WIDGET_CONTROL, /DESTROY, base
  78. ;
  79. ;    XSIZE:    The maximum width of the image that can be displayed by
  80. ;        the scrolling window.  This keyword should not be confused 
  81. ;        with the visible size of the image, controlled by the XVISIBLE
  82. ;        keyword.  If XSIZE is not specified, the width of Image is 
  83. ;        used.  If Image is not specified, 256 is used.
  84. ;
  85. ;     XVISIBLE:    The width of the viewport on the scrolling window.  If this 
  86. ;        keyword is not specified, 256 is used.
  87. ;
  88. ;    YSIZE:    The maximum height of the image that can be displayed by
  89. ;        the scrolling window.  This keyword should not be confused 
  90. ;        with the visible size of the image, controlled by the YVISIBLE
  91. ;        keyword.  If YSIZE is not present the height of Image is used.
  92. ;        If Image is not specified, 256 is used.
  93. ;
  94. ;     YVISIBLE:    The height of the viewport on the scrolling window. If
  95. ;        this keyword is not present, 256 is used.
  96. ;
  97. ; OUTPUTS:
  98. ;    None.
  99. ;
  100. ; COMMON BLOCKS:
  101. ;    None.
  102. ;
  103. ; SIDE EFFECTS:
  104. ;    Widgets for displaying a very large image are created.
  105. ;    The user typically uses the window manager to destroy
  106. ;    the window, although the TOP_ID keyword can also be used to
  107. ;    obtain the widget ID to use in destroying it via WIDGET_CONTROL.
  108. ;
  109. ; RESTRICTIONS:
  110. ;    Scrolling windows don't work correctly if backing store is not 
  111. ;    provided.  They work best with window-system-provided backing store
  112. ;    (RETAIN=1), but are also usable with IDL provided backing store 
  113. ;    (RETAIN=2).
  114. ;
  115. ;    Various machines place different restrictions on the size of the
  116. ;    actual image that can be handled.
  117. ;
  118. ; MODIFICATION HISTORY:
  119. ;    7 August, 1991, Written by AB, RSI.
  120. ;    10 March, 1993, ACY, Change default RETAIN=2
  121. ;    23 Sept., 1994  KDB, Fixed Typo in comments. Fixed error in
  122. ;            Congrid call. xvisible was used instead of yvisible.
  123. ;-
  124.  
  125.  
  126. pro SLIDE_IMG_EVENT, ev
  127.   WIDGET_CONTROL, ev.top, /DESTROY
  128. end
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. pro slide_image, image, CONGRID=USE_CONGRID, ORDER=ORDER, REGISTER=REGISTER, $
  137.     RETAIN=RETAIN, SHOW_FULL=SHOW_FULL, SLIDE_WINDOW=SLIDE_WINDOW, $
  138.     XSIZE=XSIZE, XVISIBLE=XVISIBLE, YSIZE=YSIZE, YVISIBLE=YVISIBLE, $
  139.     TITLE=TITLE, TOP_ID=BASE, FULL_WINDOW=FULL_WINDOW, GROUP = GROUP
  140.  
  141.   SWIN = !D.WINDOW
  142.  
  143.   if (n_params() ne 0) then begin
  144.     image_size = SIZE(image)
  145.     if (image_size[0] ne 2) then message,'Image must be a 2-D array'
  146.     if (n_elements(XSIZE) eq 0) then XSIZE = image_size[1]
  147.     if (n_elements(YSIZE) eq 0) then YSIZE = image_size[2]
  148.   endif else begin
  149.     image_size=bytarr(1)
  150.     if (n_elements(XSIZE) eq 0) then XSIZE = 256
  151.     if (n_elements(YSIZE) eq 0) then YSIZE = 256
  152.   endelse
  153.   if (n_elements(xvisible) eq 0) then XVISIBLE=256
  154.   if (n_elements(Yvisible) eq 0) then YVISIBLE=256
  155.   if(n_elements(SHOW_FULL) eq 0) THEN SHOW_FULL = 1
  156.   if(not KEYWORD_SET(ORDER)) THEN ORDER = 0
  157.   if(not KEYWORD_SET(USE_CONGRID)) THEN USE_CONGRID = 1
  158.   if(n_elements(RETAIN) eq 0) THEN RETAIN = 2
  159.   if(n_elements(TITLE) eq 0) THEN TITLE='Slide Image'
  160.   if(not KEYWORD_SET(REGISTER)) THEN REGISTER = 0
  161.  
  162.   if (REGISTER) then begin
  163.     base = WIDGET_BASE(title=title, /COLUMN)
  164.     junk = WIDGET_BUTTON(WIDGET_BASE(base), value='Done')
  165.     ibase = WIDGET_BASE(base, /ROW)
  166.   endif else begin
  167.     base = WIDGET_BASE(title=title, /ROW)
  168.     ibase = base
  169.   endelse
  170.   ; Setting the managed attribute indicates our intention to put this app
  171.   ; under the control of XMANAGER, and prevents our draw widgets from
  172.   ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  173.   ; sets this, but doing it here prevents our own WSETs at startup from
  174.   ; having that problem.
  175.   WIDGET_CONTROL, /MANAGED, base
  176.  
  177.   if (SHOW_FULL) then begin
  178.       fbase = WIDGET_BASE(ibase, /COLUMN, /FRAME)
  179.         junk = WIDGET_LABEL(fbase, value='Full Image')
  180.         all = widget_draw(fbase,retain=retain,xsize=xvisible,ysize=yvisible)
  181.       sbase = WIDGET_BASE(ibase, /COLUMN, /FRAME)
  182.         junk = WIDGET_LABEL(sbase, value='Full Resolution')
  183.         scroll = widget_draw(sbase, retain=retain,xsize=xsize,ysize=ysize, $
  184.         /scroll, x_scroll_size=xvisible, y_scroll_size=yvisible)
  185.     WIDGET_CONTROL, /REAL, base
  186.     WIDGET_CONTROL, get_value=FULL_WINDOW, all
  187.   endif else begin
  188.     scroll = widget_draw(ibase, retain=retain, xsize=xsize, ysize=ysize, $
  189.     /frame, /scroll, x_scroll_size=xvisible, y_scroll_size=yvisible)
  190.     WIDGET_CONTROL, /REAL, base
  191.     FULL_WINDOW=-1
  192.   endelse
  193.  
  194.   WIDGET_CONTROL, get_value=SLIDE_WINDOW, scroll
  195.  
  196.   ; Show the image(s) if one is present
  197.   if (image_size[0] ne 0) then begin
  198.     if (SHOW_FULL) then begin
  199.       WSET, FULL_WINDOW
  200.       if (use_congrid) then begin
  201.     TV, congrid(image, xvisible, yvisible), ORDER=ORDER
  202.       endif else begin
  203.     TV, image, ORDER=ORDER
  204.       endelse
  205.     endif
  206.     WSET, SLIDE_WINDOW
  207.     TV, image, ORDER=ORDER
  208.   endif
  209.   if (n_elements(group) eq 0) then group=base
  210.   WSET, SWIN
  211.  
  212.   if (REGISTER) then XMANAGER, 'SLIDE_IMAGE', base, event='SLIDE_IMG_EVENT', $
  213.     GROUP_LEADER = GROUP, /NO_BLOCK
  214.  
  215. end
  216.